#include <cstdio>
#include <cstring>

const int N = 1000005;
int n, l1, l2, top, ans[N], nxt[N], lst[N];
char s[N], t[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("CppTest.in", "r", stdin);
  freopen("CppTest.out", "w", stdout);
#endif
#endif

  scanf("%s", s + 1);
  l1 = strlen(s + 1);
  scanf("%s", t + 1);
  l2 = strlen(t + 1);
  for (int i = 2, j = 0; i <= l2; ++i) {
    while (j && t[i] != t[j + 1]) j = nxt[j];
    if (t[i] == t[j + 1]) j++;
    nxt[i] = j;
  }
  for (int i = 1, j = 0; i <= l1; ++i) {
    ans[++top] = i;
    while (j && s[i] != t[j + 1]) j = nxt[j];
    if (s[i] == t[j + 1]) j++;
    lst[i] = j;
    if (j == l2) {
      top -= l2;
      j = lst[ans[top]];
    }
  }
  for (int i = 1; i <= top; ++i) putchar(s[ans[i]]);
  return 0;
}